<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Restaurant_class extends CI_Model {
	
	
	public function save_resto_details($post)
	{
		$getAccType = $this->session->userdata('intAccountType');
		if($getAccType=='2')
		{
			$intBranchOwner = $this->session->userdata('intUserID');
		}
		else
		{
			$intBranchOwner = stripslashes(filter_var($post['intRestoOwer'], FILTER_SANITIZE_STRING));
		}
		$strRestoName = stripslashes(filter_var($post['strRestoName'], FILTER_SANITIZE_STRING));
		$strBranchName = stripslashes(filter_var($post['strBranchName'], FILTER_SANITIZE_STRING));
		$strRestoDescr = $post['strRestoDescr'];
		$strAddress = stripslashes(filter_var($post['strAddress'], FILTER_SANITIZE_STRING));
		$strCity = stripslashes(filter_var($post['strCity'], FILTER_SANITIZE_STRING));
		$country = stripslashes(filter_var($post['country'], FILTER_SANITIZE_STRING));
		$strLatLng = stripslashes(filter_var($post['strLatLng'], FILTER_SANITIZE_STRING));
		$strMobile = stripslashes(filter_var($post['strMobile'], FILTER_SANITIZE_STRING));
		$strLandline = stripslashes(filter_var($post['strLandline'], FILTER_SANITIZE_STRING));
		$strEmail = stripslashes(filter_var($post['strEmail'], FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoOwner' => $intBranchOwner,
				'strRestoName' => $strRestoName,
				'strBranchOwner' => 0,
				'strBranchName' => $strBranchName,
				'strRestoBranchFlag' => 0,
				'strRestoMainBranchID' => 0,
				'strRestoAddress' => $strAddress,
				'strRestoCity' => $strCity,
				'strRestoCountry' => $country,
				'strLatLng' => $strLatLng,
				'strRestoDescr' => $strRestoDescr,
				'strRestoMobile' => $strMobile,
				'strRestoLandline' => $strLandline,
				'strRestoEmail' => $strEmail,
				'intRestoDeleted' => 0,
				'dateRestoCreated' => date('Y-m-d H:i:s')
		);
				
		$this->db->insert('summ_restaurants', $data);
		
		if($this->db->_error_number()==0)
		{
			$data = array(
				'intStatus'=> 1,
				'picMsg'=> ''
			); // Success
			$saveRestoDetails = array('picMsg'=>'');
			$intRestoID = $this->db->insert_id();
			$this->session->set_userdata('intRestoID', $intRestoID);
			$this->session->set_userdata('intRestoOwer', '');
			$this->session->set_userdata('intRestoOwerName', '');
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	public function save_resto_thumb($intRestoID, $strRestoThumb)
	{
		$intRestoID = stripslashes(filter_var($intRestoID, FILTER_SANITIZE_STRING));
		$strRestoThumb = stripslashes(filter_var($strRestoThumb, FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoIDThumb' => $intRestoID,
				'strRestoThumb' => $strRestoThumb
		);
				
		$this->db->insert('summ_restaurants_thumb', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	public function save_resto_banner($intRestoID, $strRestoBanner)
	{
		$intRestoID = stripslashes(filter_var($intRestoID, FILTER_SANITIZE_STRING));
		$strRestoBanner = stripslashes(filter_var($strRestoBanner, FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoIDBanner' => $intRestoID,
				'strRestoBanner' => $strRestoBanner
		);
				
		$this->db->insert('summ_restaurants_banner', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	public function save_resto_assets($intRestoID, $strRestoAsset)
	{
		$intRestoID = stripslashes(filter_var($intRestoID, FILTER_SANITIZE_STRING));
		$strRestoAsset = stripslashes(filter_var($strRestoAsset, FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoIDAssets' => $intRestoID,
				'strRestoAssets' => $strRestoAsset
		);
				
		$this->db->insert('summ_restaurants_assets', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	public function main_branch_exist()
	{
		$intBranchOwner = $this->session->userdata('intUserID');
		
		$this->db->where('strRestoOwner',$intBranchOwner);
		$query = $this->db->get('restaurants');
		if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
	}
	public function get_main_branch()
	{
		$intBranchOwner = $this->session->userdata('intUserID');
		
		$this->db->select('*');
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strRestoOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->where(array('restaurants.strRestoOwner'=>$intBranchOwner, 'restaurants.strRestoBranchFlag'=>0, 'restaurants.intRestoDeleted'=>0));
		$query = $this->db->get()->result_array();
		$query = current($query);
			
		if($query['intRestoID']==""){
			return 0;
		}else{
			return $query;
		}
	}
	public function list_branches()
	{
		$this->db->select('*');
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strBranchOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->where(array('restaurants.strRestoBranchFlag'=>1,'restaurants.intRestoDeleted'=>0));
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
	public function list_main_branch($offset = null, $limit = null)
	{
		$this->db->select('*');
		$this->db->limit($limit, $offset);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strRestoOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->join('restaurants_assets', 'restaurants.intRestoID = restaurants_assets.strRestoIDAssets', 'left');
		$query = $this->db->where(array('restaurants.strRestoBranchFlag'=>0, 'restaurants.intRestoDeleted'=>0));
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
	public function list_main_branch_total()
	{
		$this->db->select('*')->from('restaurants');
		$this->db->where(array('strRestoBranchFlag'=>0,'intRestoDeleted'=>0));
		$result = $this->db->count_all_results();
		
		return $result;
	}
	public function list_branch_resto($offset = null, $limit = null)
	{
		$intBranchOwner = $this->session->userdata('intUserID');
		
		$this->db->select('*');
		$this->db->limit($limit, $offset);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strBranchOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->where(array('restaurants.strRestoOwner'=>$intBranchOwner, 'restaurants.strRestoBranchFlag'=>1,'restaurants.intRestoDeleted'=>0));
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
	public function get_branch_total()
	{
		$intRestoOwer = $this->session->userdata('intUserID');
		
		$this->db->select('*')->from('restaurants');
		$this->db->where(array('strRestoOwner'=>$intRestoOwer, 'strRestoBranchFlag'=>1,'intRestoDeleted'=>0));
		$result = $this->db->count_all_results();
		
		return $result;
	}
	public function is_resto_owner($mainBranchID)
	{
		$intBranchOwner = $this->session->userdata('intUserID');
		
		$this->db->where(array('intRestoID'=>$mainBranchID, 'strRestoOwner'=>$intBranchOwner, 'strRestoBranchFlag'=>0));
		$query = $this->db->get('restaurants');
		if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
	}
	public function is_branch_owner()
	{
		$intRestoOwer = $this->session->userdata('intUserID');
		
		$this->db->where(array('strBranchOwner'=>$intRestoOwer, 'strRestoBranchFlag'=>1));
		$query = $this->db->get('restaurants');
		if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
	}
	public function save_branch_details($post, $mainBranchID)
	{
		$intRestoOwer = $this->session->userdata('intUserID');
		$strBranchOwner = $this->session->userdata('intRestoOwer');
		$strRestoMainBranchID = stripslashes(filter_var($post['strMainBranchID'], FILTER_SANITIZE_STRING));
		$strRestoName = stripslashes(filter_var($post['strRestoName'], FILTER_SANITIZE_STRING));
		$strBranchName = stripslashes(filter_var($post['strBranchName'], FILTER_SANITIZE_STRING));
		$strRestoDescr = $post['strRestoDescr'];
		$strAddress = stripslashes(filter_var($post['strAddress'], FILTER_SANITIZE_STRING));
		$strCity = stripslashes(filter_var($post['strCity'], FILTER_SANITIZE_STRING));
		$country = stripslashes(filter_var($post['country'], FILTER_SANITIZE_STRING));
		$strLatLng = stripslashes(filter_var($post['strLatLng'], FILTER_SANITIZE_STRING));
		$strMobile = stripslashes(filter_var($post['strMobile'], FILTER_SANITIZE_STRING));
		$strLandline = stripslashes(filter_var($post['strLandline'], FILTER_SANITIZE_STRING));
		$strEmail = stripslashes(filter_var($post['strEmail'], FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoOwner' => $intRestoOwer,
				'strRestoName' => $strRestoName,
				'strBranchOwner' => $strBranchOwner,
				'strBranchName' => $strBranchName,
				'strRestoBranchFlag' => 1,
				'strRestoMainBranchID' => $strRestoMainBranchID,
				'strRestoAddress' => $strAddress,
				'strRestoCity' => $strCity,
				'strRestoCountry' => $country,
				'strLatLng' => $strLatLng,
				'strRestoDescr' => $strRestoDescr,
				'strRestoMobile' => $strMobile,
				'strRestoLandline' => $strLandline,
				'strRestoEmail' => $strEmail,
				'intRestoDeleted' => 0,
				'dateRestoCreated' => date('Y-m-d H:i:s')
		);
				
		$this->db->insert('restaurants', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
			$intRestoID = $this->db->insert_id();
			$this->session->set_userdata('intRestoID', $intRestoID);
			$this->session->set_userdata('intRestoOwer', '');
			$this->session->set_userdata('intRestoOwerName', '');
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	public function update_branch_details($post)
	{
		$intRestoID = stripslashes(filter_var($post['intRestoID'], FILTER_SANITIZE_STRING));
		$strRestoName = stripslashes(filter_var($post['strRestoName'], FILTER_SANITIZE_STRING));
		$strBranchName = stripslashes(filter_var($post['strBranchName'], FILTER_SANITIZE_STRING));
		$strRestoDescr = $post['strRestoDescr'];
		$strRestoAddress = stripslashes(filter_var($post['strAddress'], FILTER_SANITIZE_STRING));
		$strRestoCity = stripslashes(filter_var($post['strCity'], FILTER_SANITIZE_STRING));
		$country = stripslashes(filter_var($post['country'], FILTER_SANITIZE_STRING));
		$strLatLng = stripslashes(filter_var($post['strLatLng'], FILTER_SANITIZE_STRING));
		$strMobile = stripslashes(filter_var($post['strMobile'], FILTER_SANITIZE_STRING));
		$strLandline = stripslashes(filter_var($post['strLandline'], FILTER_SANITIZE_STRING));
		$strEmail = stripslashes(filter_var($post['strEmail'], FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoName' => $strRestoName,
				'strBranchName' => $strBranchName,
				'strRestoAddress' => $strRestoAddress,
				'strRestoCity' => $strRestoCity,
				'strRestoCountry' => $country,
				'strLatLng' => $strLatLng,
				'strRestoDescr' => $strRestoDescr,
				'strRestoMobile' => $strMobile,
				'strRestoLandline' => $strLandline,
				'strRestoEmail' => $strEmail
		);
		$this->db->where(array('intRestoID'=>$intRestoID));
		$this->db->update('restaurants', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
			$data['picMsg'] = '';
		}
		else
		{
			$data['intStatus'] = 0; // Failed
			$data['picMsg'] = '';
		}
		return $data;
	}
	public function get_my_branch()
	{
		$intBranchOwner = $this->session->userdata('intUserID');
		
		$this->db->select('*');
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strBranchOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->where(array('restaurants.strBranchOwner'=>$intBranchOwner, 'restaurants.strRestoBranchFlag'=>1,'restaurants.intRestoDeleted'=>0));
		$query = $this->db->get()->result_array();
		$query = current($query);
			
		if($query['intRestoID']==""){
			return 0;
		}else{
			return $query;
		}
	}
	public function is_resto_exist($intRestoID)
	{
		$intRestoOwer = $this->session->userdata('intUserID');

		$this->db->where(array('strRestoOwner'=>$intRestoOwer, 'strRestoBranchFlag'=>0));
		$this->db->or_where(array('strBranchOwner'=>$intRestoOwer, 'strRestoBranchFlag'=>1));
		$query = $this->db->get('restaurants');
		if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
	}
	public function the_resto_details($intRestoID)
	{
		$intRestoOwner = $this->session->userdata('intUserID');
		
		$this->db->select('*');
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strBranchOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->join('restaurants_banner', 'restaurants.intRestoID = restaurants_banner.strRestoIDBanner', 'left');
		$query = $this->db->where(array('restaurants.intRestoID'=>$intRestoID, 'restaurants.strRestoOwner'=>$intRestoOwner, 'restaurants.strRestoBranchFlag'=>0,'restaurants.intRestoDeleted'=>0));
		$query = $this->db->or_where(array('restaurants.intRestoID'=>$intRestoID, 'restaurants.strBranchOwner'=>$intRestoOwner, 'restaurants.strRestoBranchFlag'=>1));
		$query = $this->db->get()->result_array();
		$query = current($query);
			
		if($query['intRestoID']==""){
			return 0;
		}else{
			return $query;
		}	
	}
	public function update_resto_thumb($intRestoID, $strRestoThumb)
	{
		$intRestoID = stripslashes(filter_var($intRestoID, FILTER_SANITIZE_STRING));
		$strRestoThumb = stripslashes(filter_var($strRestoThumb, FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoThumb' => $strRestoThumb
		);
				
		$this->db->where(array('strRestoIDThumb'=>$intRestoID));
		$this->db->update('summ_restaurants_thumb', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	public function update_resto_banner($intRestoID, $strRestoBanner)
	{
		$intRestoID = stripslashes(filter_var($intRestoID, FILTER_SANITIZE_STRING));
		$strRestoBanner = stripslashes(filter_var($strRestoBanner, FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoBanner' => $strRestoBanner
		);
		
		$this->db->where(array('strRestoIDBanner'=>$intRestoID));
		$this->db->update('summ_restaurants_banner', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	/*public function update_resto_assets($intRestoID, $strRestoAsset)
	{
		$intRestoID = stripslashes(filter_var($intRestoID, FILTER_SANITIZE_STRING));
		$strRestoAsset = stripslashes(filter_var($strRestoAsset, FILTER_SANITIZE_STRING));
		
		$data = array(
				'strRestoAssets' => $strRestoAsset
		);
		$this->db->delete('restaurants_assets', array('strRestoIDAssets'=>$intRestoID)); 
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
		}
		else
		{
			$data['intStatus'] = 0; // Failed
			$this->db->where(array('strRestoIDAssets'=>$intRestoID));
			$this->db->insert('restaurants_assets', $data);
		}
		return $data;
	}*/
	public function delete_resto($post)
	{
		$intRestoID = stripslashes(filter_var($post['intRestoID'], FILTER_SANITIZE_STRING));
		
		$data = array(
			'intRestoDeleted' => 1
		);
		
		$this->db->where(array('intRestoID'=>$intRestoID));
		$this->db->update('restaurants', $data);
		
		if($this->db->_error_number()==0)
		{
			$data['intStatus'] = 1; // Success
		}
		else
		{
			$data['intStatus'] = 0; // Failed
		}
		return $data;
	}
	public function list_resto_assets($intRestoID)
	{
		$intRestoOwner = $this->session->userdata('intUserID');
		
		$this->db->select('*');
		$this->db->limit(5,0);
		$this->db->order_by('intAssetsID', 'RANDOM');
		$query = $this->db->from('restaurants_assets');
		$query = $this->db->where(array('strRestoIDAssets'=>$intRestoID));
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
	public function list_resto_grid($offset = null, $limit = null)
	{
		$this->db->select('*');
		$this->db->limit($limit, $offset);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strBranchOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->where(array('restaurants.intRestoDeleted'=>0));
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
	public function get_resto($intRestoID)
	{
			$this->db->select('*');
			$query = $this->db->from('restaurants');
			$query = $this->db->join('users', 'restaurants.strBranchOwner = users.intUserID', 'left');
			$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
			$query = $this->db->join('restaurants_banner', 'restaurants.intRestoID = restaurants_banner.strRestoIDBanner', 'left');
			$query = $this->db->where(array('restaurants.intRestoID'=>$intRestoID, 'restaurants.strRestoBranchFlag'=>0,'restaurants.intRestoDeleted'=>0));
			$query = $this->db->or_where(array('restaurants.intRestoID'=>$intRestoID, 'restaurants.strRestoBranchFlag'=>1));
			$query = $this->db->get()->result_array();
			$query = current($query);
				
			if($query['intRestoID']==""){
				return 0;
			}else{
				return $query;
			}	
	}
	public function view_branches($offset = null, $limit = null)
	{
		$id = $this->session->userdata('idSess');
		
		$this->db->select('*');
		$this->db->limit($limit, $offset);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strRestoOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->where(array('restaurants.strRestoMainBranchID'=>$id, 'restaurants.strRestoBranchFlag'=>1, 'restaurants.intRestoDeleted'=>0));
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
	public function get_view_branches_total($post)
	{
			$intRestoID = stripslashes(filter_var($post['intRestoID'], FILTER_SANITIZE_STRING));
		$this->db->select('*');
		$this->db->limit(5,0);
		$this->db->order_by('intAssetsID', 'RANDOM');
		$query = $this->db->from('restaurants_assets');
		$query = $this->db->where(array('strRestoIDAssets'=>$intRestoID));

		$id = $this->session->userdata('idSess');

		$this->db->select('*')->from('restaurants');
		$this->db->where(array('strRestoMainBranchID'=>$id, 'strRestoBranchFlag'=>1,'intRestoDeleted'=>0));
		$result = $this->db->count_all_results();
		
		return $result;
	}
	public function list_new_resto_grid()
	{
		$this->db->select('*');
		$this->db->limit(15, 0);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strBranchOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->where(array('restaurants.intRestoDeleted'=>0));
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
	public function resto_grid_total()
	{
		$this->db->select('*')->from('restaurants');
		$this->db->where(array('intRestoDeleted'=>0));
		$result = $this->db->count_all_results();
		
		return $result;
	}
		public function account_analysis_assets($post)
	{
			$intRestoID = stripslashes(filter_var($post['intRestoID'], FILTER_SANITIZE_STRING));
		$this->db->select('*');
		$this->db->limit(5,0);
		$this->db->order_by('intAssetsID', 'RANDOM');
		$query = $this->db->from('restaurants_assets');
		$query = $this->db->where(array('strRestoIDAssets'=>$intRestoID));
		$query = $this->db->get();
				if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
		
		public function account_summary($offset = null, $limit = null)
	{
		$today = date('Y-m-d');

		$this->db->select('*');
		$this->db->limit($limit, $offset);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strRestoOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->join('restaurants_assets', 'restaurants.intRestoID = restaurants_assets.strRestoIDAssets', 'left');
		$query = $this->db->like('restaurants.dateRestoCreated',$today);
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
		public function account_summary_total()
	{
		$today = date('Y-m-d');

		$this->db->select('*')->from('restaurants');
		$query = $this->db->like('restaurants.dateRestoCreated',$today);
		$result = $this->db->count_all_results();
		
		return $result;
	}
	
			public function account_summary_weekly($offset = null, $limit = null)
	{
		$lastweek = date('Y-m-d H:i:s',time()-(7*86400));
		$today = date('Y-m-d H:i:s');

		$this->db->select('*');
		$this->db->limit($limit, $offset);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strRestoOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->join('restaurants_assets', 'restaurants.intRestoID = restaurants_assets.strRestoIDAssets', 'left');
		$query = $this->db->where('restaurants.dateRestoCreated >= ',$lastweek);
          $query = $this->db ->where('restaurants.dateRestoCreated <= ',$today);
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
		public function account_summary_total_weekly()
	{
		$today = date('Y-m-d H:i:s',time()-(7*86400));

		$this->db->select('*')->from('restaurants');
		$query = $this->db->like('restaurants.dateRestoCreated',$today);
		$result = $this->db->count_all_results();
		
		return $result;
	}
			public function account_summary_monthly($offset = null, $limit = null)
	{
			$today = date('Y-m-');

		$this->db->select('*');
		$this->db->limit($limit, $offset);
		$query = $this->db->from('restaurants');
		$query = $this->db->join('users', 'restaurants.strRestoOwner = users.intUserID', 'left');
		$query = $this->db->join('restaurants_thumb', 'restaurants.intRestoID = restaurants_thumb.strRestoIDThumb', 'left');
		$query = $this->db->join('restaurants_assets', 'restaurants.intRestoID = restaurants_assets.strRestoIDAssets', 'left');
		$query = $this->db->like('restaurants.dateRestoCreated',$today);
		$query = $this->db->get();
		
		if ($query->num_rows() > 0){
			$result = $query->result_array();
			return $result;
		}else{
			return 0;
		}
	}
		public function account_summary_total_monthly()
	{
		$today = date('Y-m-');

		$this->db->select('*')->from('restaurants');
		$query = $this->db->like('restaurants.dateRestoCreated',$today);
		$result = $this->db->count_all_results();
		
		return $result;
	}
	
}